package com.ruoyi.project.ums.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.ums.domain.UmsSearchHistory;
import com.ruoyi.db.ums.domain.query.UmsSearchHistoryQueryVo;
import com.ruoyi.project.ums.service.UmsSearchHistoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 搜索历史Controller
 *
 * @author ruoyi
 * @date 2020-04-26
 */
@Api(tags="ums管理：搜索历史管理")
@RestController
@RequestMapping("/ums/history")
public class UmsSearchHistoryController extends BaseController
{
    @Autowired
    private UmsSearchHistoryService umsSearchHistoryService;

    @ApiOperation("查询搜索历史列表")
    @PreAuthorize("@ss.hasPermi('ums:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(UmsSearchHistoryQueryVo umsSearchHistoryQueryVo)
    {
        startPage();
        List<UmsSearchHistory> list = umsSearchHistoryService.selectUmsSearchHistoryList(umsSearchHistoryQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出搜索历史列表")
    @Log(title = "搜索历史", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ums:history:export')")
    @GetMapping("/export")
    public AjaxResult export(UmsSearchHistoryQueryVo umsSearchHistoryQueryVo)
    {
        List<UmsSearchHistory> list = umsSearchHistoryService.selectUmsSearchHistoryList(umsSearchHistoryQueryVo);
        ExcelUtil<UmsSearchHistory> util = new ExcelUtil<UmsSearchHistory>(UmsSearchHistory.class);
        return util.exportExcel(list, "history");
    }

    @ApiOperation("获取搜索历史详细信息")
    @Log(title = "搜索历史", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('ums:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(umsSearchHistoryService.selectUmsSearchHistoryById(id));
    }

    @ApiOperation("新增搜索历史")
    @Log(title = "搜索历史", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('ums:history:add')")
    @PostMapping
    public AjaxResult add(@RequestBody UmsSearchHistory umsSearchHistory)
    {
        return toAjax(umsSearchHistoryService.insertUmsSearchHistory(umsSearchHistory));
    }

    @ApiOperation("修改搜索历史")
    @Log(title = "搜索历史", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('ums:history:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody UmsSearchHistory umsSearchHistory)
    {
        return toAjax(umsSearchHistoryService.updateUmsSearchHistory(umsSearchHistory));
    }

    @ApiOperation("删除搜索历史")
    @Log(title = "搜索历史", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('ums:history:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(umsSearchHistoryService.deleteUmsSearchHistoryByIds(ids));
    }
}
